<template>
  <div class="baseConfig">
    <div class="btns">
      <el-form size="small" inline style="text-align:center">
        <el-form-item label="">
          <el-input
          placeholder="请输入内容"
           v-model="param.name" ></el-input>
        </el-form-item>
        <el-form-item>
           <el-button type="primary" size="small" icon="el-icon-search" @click="loadbaseConfig">搜索</el-button>
        </el-form-item>
      </el-form>
       
      <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="toAddHandler">新增</el-button>
    <el-button type="primary" size="small" icon="el-icon-edit-outline" @click="downloadHandler">导出</el-button>
    </div>
    
    <el-table size="small" :data="baseConfig" border stripe style="width:100%" max-height="500">
      <el-table-column type="index" index="1" label="序号"></el-table-column>
      <el-table-column label="id" prop="id" align="center"></el-table-column>
      <el-table-column label="名字" prop="name" align="center"></el-table-column>
      <el-table-column label="评估" prop="val" align="center"></el-table-column>
      <el-table-column label="介绍" prop="introduce" align="center"></el-table-column>
      <el-table-column label="操作" align="center"> 
        <template slot-scope="scope">
            <el-button type="primary" icon="el-icon-edit" circle @click="editHandler(scope.row)"></el-button>
           <el-button type="danger" icon="el-icon-delete" circle @click="deleteHandler(scope.row)"></el-button>

        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import {del,get,post} from "@/utils/request";

export default {
  data() {
    return {
      param:{},
      baseConfig:[],
    };
  },
  methods: {
    downloadHandler(){
      window.location.href="http://8.131.68.179:9999/base_config/download?name"+this.param.name;
    },
      editHandler(row){
      // 跳转到修改页面 （新增页面）
      // 携带当前行的数据
      this.$router.push({
        path:"/baseConfig/create",    //跳转的路由（前端）
        query:row   // 携带参数
      })
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://8.131.68.179:9999/base_config/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadbaseConfig();
        });
      });
    },
    toAddHandler() {
      this.$router.push("/baseConfig/create");
    },
    loadbaseConfig() {
      let url = "http://8.131.68.179:9999/base_config/select";
      get(url, this.param).then((resp) => {
        this.baseConfig = resp.data;
      });
    },
  },
     created() {
    this.loadbaseConfig();
  },
  }
</script>
<style scoped>
.btns {
  margin-bottom: 0.5em;
}
</style>
